package com.yuwj.chinaa.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.yuwj.chinaa.R;
import com.yuwj.chinaa.base.BaseActivity;
import com.yuwj.chinaa.entity.EntityGeneralAuth;
import com.yuwj.chinaa.presenter.IPresenter;
import com.yuwj.chinaa.presenter.presenterImpl.PresenterImpl;
import com.yuwj.chinaa.util.ToastUtil;

import org.json.JSONObject;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 账户实名认证成功界面
 */
public class AccountAuthenticationSuccessActivity extends BaseActivity {


    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.iv_photo)
    ImageView ivPhoto;
    @BindView(R.id.tv_username)
    TextView tvUsername;
    @BindView(R.id.tv_idcard_number)
    TextView tvIdcardNumber;
    @BindView(R.id.tv_idcard_number2)
    TextView tvIdcardNumber2;
    @BindView(R.id.tv_bank_number)
    TextView tvBankNumber;
    @BindView(R.id.tv_alipay_number)
    TextView tvAlipayNumber;
    IPresenter presenter;

    EntityGeneralAuth entityGeneralAuth;

    public static Intent createIntent(Context context) {
        return new Intent(context, AccountAuthenticationSuccessActivity.class);
    }

    @Override
    public int setCustomContentViewResourceId() {
        return R.layout.activity_account_authentication_success;
    }

    @Override
    public void initParam() {
        presenter = new PresenterImpl(this);
    }

    @Override
    public void initView() {
        tvTitle.setText("实名认证");
        Glide.with(context).load(entityUser.getPic()).placeholder(R.mipmap.ic_asset_user_photo).into(ivPhoto);
    }

    @Override
    public void initOperator() {
        presenter.isGeneralAuth(new JSONObject().toString());
    }

    public void updateAuthenUI() {
        if (entityGeneralAuth != null) {
            tvUsername.setText(entityGeneralAuth.getName());
            tvIdcardNumber.setText(entityGeneralAuth.getIdentityCard() + "");
            tvIdcardNumber2.setText(entityGeneralAuth.getIdentityCard() + "");
            tvAlipayNumber.setText(entityGeneralAuth.getAlipay() + "");
            tvBankNumber.setText(entityGeneralAuth.getBankCard() + "");
        }
    }


    @OnClick(R.id.iv_back)
    public void onViewClicked() {
        onBackPressed();
    }

    @Override
    public void onGetIsGeneralAuthSuccess(EntityGeneralAuth entityGeneralAuth) {
        super.onGetIsGeneralAuthSuccess(entityGeneralAuth);
        this.entityGeneralAuth = entityGeneralAuth;
        updateAuthenUI();
    }

    @Override
    public void onGetIsGeneralAuthFail(Exception e) {
        super.onGetIsGeneralAuthFail(e);
        ToastUtil.getInstance().shortLength(context, e.getMessage() + "");
    }
}
